//
//  cellectionView.m
//  EFExtend
//
//  Created by mac on 15/5/26.
//  Copyright (c) 2015年 Eric. All rights reserved.
//

#import "cellectionView.h"
#import "BookInfoSearchCell.h"

@interface cellectionView ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,BookInfoSearchCellDelegate>
@property (nonatomic,strong) UICollectionView *collection;
@end

@implementation cellectionView

- (void)dealloc
{
   self.collection = nil;
    HM_SUPER_DEALLOC();
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [self.customNavLeftBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [self.customNavLeftBtn setFrame:CGRectMakeBound(32, 32)];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //    layout.minimumInteritemSpacing = 20;
    layout.minimumLineSpacing = 20;
    self.collection = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
    self.collection.delegate = self;
    self.collection.dataSource = self;
    self.collection.alwaysBounceVertical = YES;
    self.collection.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collection];
    /*多选支持*/
    //    self.collection.allowsMultipleSelection = YES;
    
    
    [self.collection registerClass:[BookInfoSearchCell class] forCellWithReuseIdentifier:@"BookInfoSearchCell"];
    
    [self.collection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).offset(20);
        make.left.mas_equalTo(self.view.mas_left).offset(0);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(0);
        make.right.mas_equalTo(self.view.mas_right).offset(0);
    }];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

ON_Button(signal){
    UIButten *btn = signal.source;
    if ([signal is:[UIButten TOUCH_UP_INSIDE]]) {
        if ([btn is:@"leftBtn"]) {//customNavLeftBtn
            [self backAndRemoveWithAnimate:YES];
        }else if ([btn is:@"rightBtn"]){//customNavRightBtn
            
        }
    }
}
#pragma mark - bookinfo search cell delegate
- (void)bookInfoSearchCellTouch:(NSInteger)index{
    if (index==3||index==2) {

        NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 1)];
        [self.collection reloadSections:set];
    }else if (index==1){
        [self open:URLFOR_controllerWithNav(@"iBookSearch") name:@"search" animate:YES];
    }else{

        NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 1)];
        [self.collection reloadSections:set];
    }
}

#pragma mark - collection delegate

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell2 = nil;
    BookInfoSearchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BookInfoSearchCell" forIndexPath:indexPath];
    cell.delegate = self;
    cell2 = cell;
    return cell2;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 1;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 3;
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}
- (void)collectionView:(UICollectionView *)colView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell* cell = [colView cellForItemAtIndexPath:indexPath];
    
    
}

- (void)collectionView:(UICollectionView *)colView  didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell* cell = [colView cellForItemAtIndexPath:indexPath];
    
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section<2) {
        return;
    }
    

}

#pragma mark - layout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    return CGSizeMake(collectionView.width, 40);
}

@end
